package com.study.hot.di.dagger.dagger2;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.study.hot.R;
import com.study.hot.di.dagger.dagger2.component.DaggerActivityComponent2;
import com.study.hot.di.dagger.dagger2.model.DaggerModel;
import com.study.hot.di.dagger.dagger2.model.Dog;
import com.study.hot.di.dagger.dagger2.model.ModuleModel;
import com.study.hot.di.dagger.dagger2.model.Women;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * <pre>
 *     author : slx
 *     time   : 2020/11/25
 *     desc   :
 * </pre>
 */
public class DaggerActivity extends AppCompatActivity {

    //@Inject
    DaggerModel daggerModel;

    //@Inject
    ModuleModel moduleModel;

    //@Inject
    Women women;
    private DaggerActivityComponent2 daggerActivityComponent2;

    // 限定注入哪个具体类
    @Named("jinmao")
    @Inject
    Dog jinmao;

    @Named("erh")
    @Inject
    Dog erh;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dagger);
        // 初始化注入
        //DaggerDaggerActivityComponent.create().injectTo(this);
        // 第二种初始化方式合适使用module传值
        //DaggerDaggerActivityComponent.builder().build().injectTo(this);

        //DaggerMyComponent.create().injectTo(this);
        /*DaggerMyComponent.builder().initMoney(2)
                .build()
                .injectTo(this);*/

        //DaggerDaggerActivityComponent3.create().inject(this);

        findViewById(R.id.btn_dagger1).setOnClickListener(v -> System.out.println(daggerModel.test()));

        findViewById(R.id.btn_dagger2).setOnClickListener(v -> moduleModel.test());
        findViewById(R.id.btn_dagger3).setOnClickListener(v -> System.out.println(women.getSoul().getMoney()));
        findViewById(R.id.btn_dagger4).setOnClickListener(v -> {
            System.out.println(jinmao.getName());
            System.out.println(erh.getName());
        });

        getSupportFragmentManager().beginTransaction().replace(R.id.fl_content, new DaggerFragment()).commit();
    }

    public DaggerActivityComponent2 getDaggerActivityComponent2() {
        return daggerActivityComponent2;
    }
}
